import get_proxy_cache from "./data.cache";
import get_proxy_status from "./data.status";
import get_proxy_trigger from "./data.trigger";
import get_proxy_user from "./data.user";

/** 游戏数据中心 */
export default class GameDC {
	private static _trigger_: ReturnType<typeof get_proxy_trigger>;
	private static _status_: ReturnType<typeof get_proxy_status>;
	private static _cache_: ReturnType<typeof get_proxy_cache>;
	private static _user_: ReturnType<typeof get_proxy_user>;

	private static app_name: string;

	/** 游戏事件表 */
	public static get Trigger(){
		return GameDC._trigger_;
	}
	/** 游戏状态表 */
	public static get Status(){
		return GameDC._status_;
	}
	/** 游戏缓存表 */
	public static get Cache(){
		return GameDC._cache_;
	}
	/** 用户表 */
	public static get User(){
		return GameDC._user_;
	}

	public static get AppName(){
		return GameDC.app_name;
	}

	public static init(app_name: string){
		GameDC.app_name = app_name;
		GameDC._trigger_ = get_proxy_trigger();
		GameDC._status_ = get_proxy_status();
		GameDC._cache_ = get_proxy_cache(app_name);
		GameDC._user_ = get_proxy_user(app_name);
	}

	public static checkGuideID(id: number){
		let reg = new RegExp('(?<!\\d)'+id+'(?!\\d)', 'gm');
		return reg.test(GameDC.User.guide_record);
	}

	public static DoneGuideID(id: number){
		if(GameDC.checkGuideID(id)){
			return void 0;
		}

		if(GameDC.User.guide_record==''){
			GameDC.User.guide_record += id;
		}else{
			GameDC.User.guide_record += ':'+id;
		}
	}

	public static CleanGuideID(...list: number[]){
		if(list.length>0){
			let guid_done = GameDC.User.guide_record;
			list.forEach(id=>{
				let reg = new RegExp('(?<!\\d)'+id+'(?!\\d)', 'gm');
				guid_done = guid_done.replace(reg, '');
			});
			GameDC.User.guide_record = guid_done.replaceAll(/(?<!\d):/gm, '').replaceAll(/:(?!\d)/gm, '');
		}
	}

	public static checkTask(type: 'remove'|'round', id: number){
		return new RegExp('(?<!\\d)'+id+'(?!\\d)', 'gm').test(type=='round' ? GameDC.User.task_round : GameDC.User.task_remove);
	}

	public static recordTask(type: 'remove'|'round', id: number|string){
		let str = type=='round' ? GameDC.User.task_round : GameDC.User.task_remove;
		if(str!='') str += ';';
		if(type=='round') GameDC.User.task_round = str+id;
		else GameDC.User.task_remove = str+id;
	}
}